﻿
using FreeSql.DataAnnotations;
using System;
using System.ComponentModel.DataAnnotations;

namespace FreeSql
{

    public abstract class FullEntity : FullEntity<long>
    {

    }


    public abstract class OrgEntity : OrgEntity<long>
    {

    }


    public abstract class BaseEntity : BaseEntity<long>
    {

    }

    public abstract class BaseDisableEntity<T> : BaseEntity<T>
    {
        /// <summary>
        /// 是否禁用
        /// </summary>
        [Column(Position = -10)]
        public bool IsDisabled { get; set; } = false;
    }

    public abstract class BaseDisableEntity : BaseDisableEntity<long>
    {
        /// <summary>
        /// 是否禁用
        /// </summary>
        [Column(Position = -10)]
        public bool IsDisabled { get; set; } = false;
    }


    public abstract class BaseDisableAndAddEntity : BaseEntity<long>, IBaseAdd
    {
        /// <summary>
        /// 是否禁用
        /// </summary>
        [Column(Position = -10)]
        public bool IsDisabled { get; set; } = false;

        #region 创建人相关

        /// <summary>
        /// 创建人
        /// </summary>
        [Column(Position = -7, CanUpdate = false)]
        public long CreatedBy { get; set; } = 0;

        /// <summary>
        /// 创建人名称
        /// </summary>
        [Column(Position = -6, CanUpdate = false), MaxLength(50)]
        public string? CreatedByName { get; set; } = "";

        /// <summary>
        /// 创建时间
        /// </summary>
        [Column(Position = -5, CanUpdate = false, ServerTime = DateTimeKind.Local)]
        public DateTime CreatedTime { get; set; } = DateTime.Now;

        #endregion 创建人相关
    }

    /// <summary>
    /// 
    /// </summary>
    public abstract class EditEntity : EditEntity<long>
    {

    }

    /// <summary>
    /// 增加修改
    /// </summary>
    public abstract class AddEditEntity : AddEditEntity<long>
    {

    }

    public abstract class BaseOrgEntity : AddEditEntity<long>, IBaseOrg
    {
        /// <summary>
        /// 所属部门
        /// </summary>

        [Column(Position = -8)]
        public long? OrgId { get; set; }
    }


    public abstract class BaseRevisionEntity : BaseRevisionEntity<long>
    {

    }


    public abstract class BaseRevisionEntity<T> :
    BaseIdEntity<T>,// 主键 实现实体类
    IBaseRevision
    {

        /// <summary>
        /// 乐观锁 即是在数据记录版本号
        /// </summary>
        [Column(Position = -13, IsVersion = true)]
        public int Revision { get; set; }

    }



    public abstract class BaseEntity<T> :
      BaseIdEntity<T>,// 主键 实现实体类
      IBaseRevision,
      IBaseSoftDelete
    {

        /// <summary>
        /// 乐观锁 即是在数据记录版本号
        /// </summary>
        [Column(Position = -13, IsVersion = true)]
        public int Revision { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>

        [Column(Position = -11)]
        public bool IsDeleted { get; set; } = false;

    }


    public abstract class EditEntity<T> : BaseEntity<T>,
        IBaseEdit
    {
        #region 更新人相关
        /// <summary>
        /// 更新人
        /// </summary>
        [Column(Position = -4, CanInsert = false)]
        public long? UpdatedBy { get; set; }

        /// <summary>
        /// 更新人名称
        /// </summary>
        [Column(Position = -3, CanInsert = false)]
        public string? UpdatedByName { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        [Column(Position = -2, CanInsert = false, ServerTime = DateTimeKind.Local)]


        public DateTime? UpdatedTime { get; set; }

        #endregion 更新人相关
    }

    public abstract class AddEditEntity<T> : EditEntity<T>, IBaseAdd
    {
        #region 创建人相关

        /// <summary>
        /// 创建人
        /// </summary>
        [Column(Position = -7, CanUpdate = false)]
        public long CreatedBy { get; set; } = 0;

        /// <summary>
        /// 创建人名称
        /// </summary>
        [Column(Position = -6, CanUpdate = false), MaxLength(50)]
        public string? CreatedByName { get; set; } = "";

        /// <summary>
        /// 创建时间
        /// </summary>
        [Column(Position = -5, CanUpdate = false, ServerTime = DateTimeKind.Local)]
        public DateTime CreatedTime { get; set; } = DateTime.Now;

        #endregion 创建人相关
    }

    /// <summary>
    /// 有禁用状态，但没有groupId
    /// </summary>
    public abstract class DisableEntity : DisableEntity<long>
    {

    }
    public abstract class DisableEntity<T> :
      AddEditEntity<T>,// 主键 实现实体类
      IBaseDisable
    {
        /// <summary>
        /// 是否禁用
        /// </summary>
        [Column(Position = -10)]
        public bool IsDisabled { get; set; } = false;
    }
    /// <summary>
    /// 最全公共属性基类，业务数据实体建议继承此类
    /// 包括了ID、创建人相关、编辑人相关、软删除、禁用标记、乐观锁、数据归属组
    /// </summary>
    public abstract class OrgEntity<T> :
        AddEditEntity<T>,// 主键 实现实体类
        IBaseOrg
    {
        /// <summary>
        /// 数据归属组 为数据做数据权限提供方便
        /// </summary>
        [Column(Position = -8)]
        public long? OrgId { get; set; }
    }
    public abstract class FullEntity<T> :
      OrgEntity<T>,// 主键 实现实体类
          IBaseDisable
    {
        /// <summary>
        /// 是否禁用
        /// </summary>
        [Column(Position = -10)]
        public bool IsDisabled { get; set; } = false;

    }


}
